/***********************************************************************
 * SpaceGame class
 * 
 * Implements the game state and the game initialization
 *
 * Signature:
 *  public static Clock clock ();
 *  public static boolean isGodMode ();
 *  public static void toggleGodMode ();
 *  public static Map map ();
 *  public static void updateMap (Map newmap);
 *  public static Player me ();
 *  public static void main (String[] argv);
 ***********************************************************************/

import java.util.*;
import java.io.*;

import org.json.JSONObject;

public class SpaceGame {
  
  private static GameState state = GameState.createDefault();
  
  public static Clock clock() {
    return state.clock();
  }
  
  public static boolean isGodMode() {
    return state.isGodMode();
  }
  
  public static void toggleGodMode() {
    state.toggleGodMode();
  }
  
  public static Map map() {
    return state.map();
  }
  
  public static void updateMap(Map m) {
    state.updateMap(m);
  }
  
  public static Player me() {
    return state.me();
  }
  
  public static void loadGameStateFromJSON(JSONObject json) {
    state = GameState.fromJSON(json);
    clock().registerObserver(TimeReporter.create());
  }
  
  public static String toJSONString() {
    return state.toJSONString();
  }
  
  /*
   * public static Map mapFromArray (int xsize, int ysize, Artifact[] art, int
   * min, int max) { if (min==max) return Map.artifact(xsize,ysize,art[min]);
   * return Map.merge(mapFromArray(xsize,ysize,art,min,(max-min)/2+min),
   * mapFromArray(xsize,ysize,art,(max-min)/2+min+1,max)); }
   */

  public static void main(String[] argv) {
    /*
     * if (argv.length > 0 && argv[0].equals("--debug"))
     * World.setDebugFlag(true);
     */

    System.out.println("The CS 3500 Space Game, v1.0 (November 2009)");
    System.out.println("Type ? for a list of commands");
    
    state.setMe(Player.create("Defiant", Coord.create(10, 10), 100));
    
    Planet.create("Euphor", Coord.create(20, 8));
    Ship.create("Arcadia", Coord.create(10, 1), 50);
    Star.create("Rao", Coord.create(11, 11));
    Base.create("Babylon 5", Coord.create(25, 3), 100);
    Star.create("Sol", Coord.create(0, 0));
    AutonomousEnemy.create("Cylon", Coord.create(20, 10), 100);
    
    // // Register this action first
    // // This will be the first thing executed at every turn
    // Clock.registerAction(new PrintTickAction());
    
    // // Create the world
    // createWorld("blubbering-fool");
    
    // // Create the vocabulary to control artifacts
    // createVocabulary();
    
    clock().registerObserver(TimeReporter.create());
    
    InteractionLoop loop = InteractionLoop.create();
    loop.registerCommand(Quit.create());
    loop.registerCommand(Scan.create());
    loop.registerCommand(God.create());
    loop.registerCommand(Wait.create());
    loop.registerCommand(Move.create());
    loop.registerCommand(Fire.create());
    loop.registerCommand(Orbit.create());
    loop.registerCommand(Save.create());
    loop.registerCommand(Load.create());
    loop.run();
  }
  
  public static void loadGameState(String readLine) {
    // TODO Auto-generated method stub
    
  }
  
}
